package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TeaShop;
import com.ruoyi.system.domain.TeaShopEmployee;
import com.ruoyi.system.domain.TeaShopInventory;
import com.ruoyi.system.domain.TeaShopWorkPlace;
import com.ruoyi.system.service.ITeaShopEmployeeService;
import com.ruoyi.system.service.ITeaShopService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.xmlbeans.impl.schema.StscChecker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 茶店信息Controller
 * 
 * @author ruoyi
 * @date 2023-12-30
 */
@Controller
@RequestMapping("/system/shop")
public class TeaShopController extends BaseController
{
    private String prefix = "system/shop";

    @Autowired
    private ITeaShopService teaShopService;
    @Autowired
    private ITeaShopEmployeeService teaShopEmployeeService;

    @RequiresPermissions("system:shop:view")
    @GetMapping()
    public String shop()
    {
        return prefix + "/shop";
    }

    /**
     * 查询茶店信息列表
     */
    @RequiresPermissions("system:shop:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeaShop teaShop)
    {
        startPage();
        List<TeaShop> list = teaShopService.selectTeaShopList(teaShop);
        return getDataTable(list);
    }

    /**
     * 导出茶店信息列表
     */
    @RequiresPermissions("system:shop:export")
    @Log(title = "茶店信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeaShop teaShop)
    {
        List<TeaShop> list = teaShopService.selectTeaShopList(teaShop);
        ExcelUtil<TeaShop> util = new ExcelUtil<TeaShop>(TeaShop.class);
        return util.exportExcel(list, "茶店信息数据");
    }

    /**
     * 新增茶店信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存茶店信息
     */
    @RequiresPermissions("system:shop:add")
    @Log(title = "茶店信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeaShop teaShop)
    {
        return toAjax(teaShopService.insertTeaShop(teaShop));
    }

    /**
     * 修改茶店信息
     */
    @RequiresPermissions("system:shop:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TeaShop teaShop = teaShopService.selectTeaShopById(id);
        mmap.put("teaShop", teaShop);
        return prefix + "/edit";
    }

    /**
     * 修改保存茶店信息
     */
    @RequiresPermissions("system:shop:edit")
    @Log(title = "茶店信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeaShop teaShop)
    {
        return toAjax(teaShopService.updateTeaShop(teaShop));
    }

    /**
     * 删除茶店信息
     */
    @RequiresPermissions("system:shop:remove")
    @Log(title = "茶店信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(teaShopService.deleteTeaShopByIds(ids));
    }

    /**
     * 分配员工
     */
    @GetMapping("/allocateEmployees/{teaShopId}")
    public String allocateEmployees(@PathVariable("teaShopId") Long teaShopId, ModelMap mmap)
    {
        mmap.put("teaShop", teaShopService.selectTeaShopById(teaShopId));
        return prefix + "/allocateEmployees";
    }
    /**
     * 查询已分配员工列表
     */
    @PostMapping("/allocateEmployees/allocatedList")
    @ResponseBody
    public TableDataInfo allocatedList(TeaShopWorkPlace teaShopWorkPlace)
    {
        startPage();
        List<TeaShopEmployee> list = teaShopService.selectAllocatedList(teaShopWorkPlace);
        return getDataTable(list);
    }

    /**
     * 取消分配
     */
    @PostMapping("/allocateEmployees/cancel")
    @ResponseBody
    public AjaxResult cancelAllocateEmployees(TeaShopWorkPlace teaShopWorkPlace)
    {
        return toAjax(teaShopService.deleteAllocateEmployee(teaShopWorkPlace));
    }

    /**
     * 批量取消分配
     */
    @PostMapping("/allocateEmployees/cancelAll")
    @ResponseBody
    public AjaxResult cancelAllocateEmployeesAll(Long teaShopId, String employeeIds)
    {
        return toAjax(teaShopService.deleteAllocateEmployees(teaShopId, employeeIds));
    }


    /**
     * 未分配员工
     */
    @GetMapping("/unAllocateEmployees/{teaShopId}")
    public String unAllocateEmployees(@PathVariable("teaShopId") Long teaShopId, ModelMap mmap)
    {
        mmap.put("teaShop", teaShopService.selectTeaShopById(teaShopId));
        return prefix + "/unAllocateEmployees";
    }
    /**
     * 查询未分配员工列表
     */
    @PostMapping("/unAllocateEmployees/unAllocatedList")
    @ResponseBody
    public TableDataInfo unAllocatedList(TeaShopWorkPlace teaShopWorkPlace)
    {
        startPage();
        List<TeaShopEmployee> list = teaShopService.selectUnAllocatedList(teaShopWorkPlace);
        return getDataTable(list);
    }

    /**
     * 批量分配员工
     */
    @PostMapping("/unAllocateEmployees/selectUnAllocateEmployeesAll")
    @ResponseBody
    public AjaxResult selectUnAllocateEmployeesAll(Long teaShopId, String employeeIds)
    {
        return toAjax(teaShopService.insertUnAllocateEmployees(teaShopId, employeeIds));
    }
    /**
     * 茶店库存
     */
    @GetMapping("/teaShopInventory/{teaShopId}")
    public String teaShopInventory(@PathVariable("teaShopId") Long teaShopId, ModelMap mmap)
    {
        mmap.put("teaShop", teaShopService.selectTeaShopById(teaShopId));
        return prefix + "/teaShopInventory";
    }

    /**
     * 查询茶店库存列表
     */
    @PostMapping("/teaShopInventory/teaShopInventoryList")
    @ResponseBody
    public TableDataInfo teaShopInventoryList(TeaShopInventory teaShopInventory)
    {
        startPage();
        List<TeaShopInventory> list = teaShopService.selectTeaShopInventoryList(teaShopInventory);
        return getDataTable(list);
    }

    @GetMapping("/teaShopInventory/deliveryInformation/{teaShopId}")
    public String deliveryInformation(@PathVariable("teaShopId") Long teaShopId, ModelMap mmap)
    {
        mmap.put("teaShop", teaShopService.selectTeaShopById(teaShopId));
        return prefix + "/deliveryInformation";
    }
    @GetMapping("/teaShopInventory/consume/{teaShopId}")
    public String consume(@PathVariable("teaShopId") Long teaShopId, ModelMap mmap)
    {
        mmap.put("teaShop", teaShopService.selectTeaShopById(teaShopId));
        return prefix + "/consume";
    }
}
